package net.sx.minemodule.mvp.activities;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.homegoods.aroutercomment.UserService;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.resource.SpacesItemDecoration;
import com.kedll.library.base.KRefreshListActivity;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.util.MyUtils;
import com.kedll.library.util.RxBus;
import com.trello.rxlifecycle2.android.ActivityEvent;

import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityMineMsgPushBinding;
import net.sx.minemodule.mvp.event.MsgPushEvent;
import net.sx.minemodule.mvp.presenters.MineMsgPushPresenter;


/**
 * 消息推送
 *
 * @author 11470
 */
@Route(path = ARouterPath.PATH_MINE_MSG_PUSH)
public class MineMsgPushActivity extends MyBaseFragmentActivity<MineActivityMineMsgPushBinding, MineMsgPushPresenter> {
    private RecyclerView recyclerView;

    @Autowired
    public UserService userService;

    //    SettingPush settingPush;


    @Override
    protected int getLayout() {
        return R.layout.mine_activity_mine_msg_push;
    }

    @SuppressLint("CheckResult")
    @Override
    protected void initEvent() {
        //接收区域选择结果
        RxBus.getDefault().toFlowable(MsgPushEvent.class)
                .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(event -> {
                    userService.setUserModel(event.json);
                });
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        recyclerView = mBinding.mineMsgPushRecyclerView;
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.setLayoutManager(MyUtils.getFlexBoxLayoutManager(this));
        mPresenter.getMsgPushList(userService.getPushSign(), this);
        recyclerView.setAdapter(mPresenter.getAdapter());
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        ARouter.getInstance().inject(this);
        setTitle("消息推送");
    }

    @Override
    protected MineMsgPushPresenter getPresenter() {
        return new MineMsgPushPresenter();
    }


    @Override
    protected void onStop() {
        super.onStop();
    }
}
